package com.service.impl;

import com.dao.RbacManagerDao;
import com.entity.RbacManager;
import com.entity.ResponseEntity;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RbacManagerServiceImpl implements RbacManagerService {
    private RbacManagerDao rbacManagerDao;

    @Autowired
    public void setRbacManagerDao(RbacManagerDao rbacManagerDao) {
        this.rbacManagerDao = rbacManagerDao;
    }

    @Override
    public ResponseEntity addOne(RbacManager rbacManager) {
        int i = rbacManagerDao.addOne(rbacManager);
        if (i > 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.FAIL;
    }

    @Override
    public ResponseEntity deleteOne(int id) {
        int i = rbacManagerDao.deleteOne(id);
        if (i > 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.FAIL;
    }

    @Override
    public ResponseEntity updateOne(RbacManager rbacManager) {
        int i = rbacManagerDao.updateOne(rbacManager);
        if (i > 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.FAIL;
    }

    @Override
    public ResponseEntity findByOne(int id) {
        RbacManager rbacManager = rbacManagerDao.findOne(id);

        return new ResponseEntity<>(200,"查询成功",rbacManager);
    }

    @Override
    public ResponseEntity findAll(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<RbacManager> all = rbacManagerDao.findAll();
        PageInfo<RbacManager> pageInfo = PageInfo.of(all);
        return new ResponseEntity<>(200,"查询成功",pageInfo);
    }

    @Override
    public ResponseEntity findAll() {
        List<RbacManager> list = rbacManagerDao.findAll();
        return new ResponseEntity(200,"查询成功",list);
    }

    @Override
    public RbacManager login(String username, String password) {
        return rbacManagerDao.login(username,password);
    }

    @Override
    public RbacManager findOne(String username) {
        return rbacManagerDao.findUser(username);
    }

    @Override
    public ResponseEntity<RbacManager> search(String account, String status) {
        List<RbacManager> search = rbacManagerDao.search(account,status);
        return new ResponseEntity(200,"查询成功",search);
    }
}
